<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="com.example.dao.ProductDao" %>
<%@ page import="com.example.util.DBUtil" %>
<%@ page import="com.example.domain.Product" %>
<%@ page import="java.util.List" %>
<%@ page import="java.sql.Connection" %>
<!DOCTYPE html>
<html>
<head>
    <title>购物网 - 首页</title>
    <link rel="stylesheet" href="assets/css/styles.css">
    <style>
        /* 主体内容布局 */
        .main-content {
            display: flex;
            gap: 20px;
            margin-top: 20px;
            flex-wrap: wrap;
        }
        
        /* 左侧分类导航 */
        .sidebar {
            width: 200px;
            background: var(--white-color);
            border-radius: var(--border-radius-lg);
            padding: 15px;
            box-shadow: var(--shadow);
            height: fit-content;
            transition: var(--transition);
        }
        
        .sidebar:hover {
            box-shadow: var(--shadow-md);
        }
        
        .category-list-vertical {
            list-style: none;
        }
        
        .category-item-vertical {
            padding: 10px 0;
            border-bottom: 1px solid var(--border-color);
            transition: var(--transition);
        }
        
        .category-item-vertical:last-child {
            border-bottom: none;
        }
        
        .category-item-vertical:hover {
            background-color: var(--gray-50);
            border-radius: var(--border-radius);
            padding-left: 5px;
        }
        
        .category-item-vertical a {
            text-decoration: none;
            color: var(--gray-700);
            display: flex;
            align-items: center;
            transition: var(--transition);
            padding: 0 10px;
        }
        
        .category-item-vertical a:hover {
            color: var(--primary-color);
        }
        
        .category-icon-vertical {
            margin-right: 10px;
            font-size: 18px;
            display: flex;
            align-items: center;
            justify-content: center;
            width: 24px;
        }
        
        /* 右侧用户信息面板 */
        .user-panel {
            width: 250px;
            background: var(--white-color);
            border-radius: var(--border-radius-lg);
            padding: 20px;
            box-shadow: var(--shadow);
            height: fit-content;
            transition: var(--transition);
        }
        
        .user-panel:hover {
            box-shadow: var(--shadow-md);
        }
        
        .panel-title {
            font-size: 1.2rem;
            font-weight: bold;
            margin-bottom: 15px;
            padding-bottom: 10px;
            border-bottom: 2px solid var(--primary-color);
            color: var(--gray-800);
        }
        
        .panel-section {
            margin-bottom: 20px;
        }
        
        .panel-section h4 {
            margin: 0 0 10px 0;
            color: var(--gray-600);
            font-size: 1rem;
            font-weight: 600;
        }
        
        .panel-links {
            list-style: none;
        }
        
        .panel-links li {
            margin-bottom: 8px;
            transition: var(--transition);
        }
        
        .panel-links li:hover {
            background-color: var(--gray-50);
            border-radius: var(--border-radius);
            padding-left: 5px;
        }
        
        .panel-links a {
            text-decoration: none;
            color: var(--gray-700);
            display: flex;
            align-items: center;
            transition: var(--transition);
            padding: 6px 10px;
        }
        
        .panel-links a:hover {
            color: var(--primary-color);
        }
        
        .panel-icon {
            margin-right: 8px;
            font-size: 16px;
            display: flex;
            align-items: center;
            justify-content: center;
            width: 24px;
        }
        
        /* 中间主要内容区域 */
        .content-area {
            flex: 1;
            min-width: 300px;
        }
        
        /* 轮播图样式 */
        .hero-section {
            margin-bottom: 20px;
            position: relative;
            border-radius: var(--border-radius-lg);
            overflow: hidden;
            box-shadow: var(--shadow);
            transition: var(--transition);
        }
        
        .hero-section:hover {
            box-shadow: var(--shadow-md);
        }
        
        .hero-banner {
            width: 100%;
            height: 350px;
            background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 2rem;
            font-weight: bold;
            position: relative;
            overflow: hidden;
        }
        
        .hero-banner::before {
            content: '';
            position: absolute;
            width: 120%;
            height: 120%;
            background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0) 70%);
            transform: rotate(-45deg) translateX(-50%) translateY(-50%);
            animation: shimmer 3s infinite alternate;
        }
        
        @keyframes shimmer {
            0% { transform: rotate(-45deg) translateX(-100%) translateY(-50%); }
            100% { transform: rotate(-45deg) translateX(0%) translateY(-50%); }
        }
        
        .hero-content {
            position: relative;
            z-index: 1;
            text-align: center;
            max-width: 80%;
        }
        
        .hero-title {
            font-size: 2.5rem;
            margin-bottom: 1rem;
            font-weight: 700;
            text-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        
        .hero-subtitle {
            font-size: 1.2rem;
            margin-bottom: 1.5rem;
            font-weight: 400;
            opacity: 0.9;
        }
        
        /* 热门推荐 */
        .section-title {
            font-size: 1.5rem;
            font-weight: bold;
            margin: 25px 0 15px 0;
            padding-bottom: 10px;
            border-bottom: 2px solid var(--primary-color);
            color: var(--gray-800);
            position: relative;
        }
        
        .section-title::after {
            content: '';
            position: absolute;
            bottom: -2px;
            left: 0;
            width: 60px;
            height: 2px;
            background-color: var(--primary-color);
            border-radius: 1px;
        }
        
        /* 特色服务 */
        .feature-services {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 20px;
            margin: 30px 0;
        }
        
        .service-card {
            background: var(--white-color);
            border-radius: var(--border-radius);
            padding: 20px;
            text-align: center;
            box-shadow: var(--shadow-sm);
            transition: var(--transition);
        }
        
        .service-card:hover {
            transform: translateY(-5px);
            box-shadow: var(--shadow-md);
        }
        
        .service-icon {
            font-size: 2rem;
            margin-bottom: 10px;
            color: var(--primary-color);
        }
        
        .service-title {
            font-size: 1.1rem;
            font-weight: 600;
            margin-bottom: 5px;
            color: var(--gray-800);
        }
        
        .service-desc {
            font-size: 0.9rem;
            color: var(--gray-600);
        }
        
        /* 响应式调整 */
        @media (max-width: 1024px) {
            .sidebar {
                width: 180px;
            }
            
            .user-panel {
                width: 220px;
            }
        }
        
        @media (max-width: 768px) {
            .main-content {
                flex-direction: column;
            }
            
            .sidebar,
            .user-panel {
                width: 100%;
            }
            
            .hero-banner {
                height: 250px;
            }
            
            .hero-title {
                font-size: 2rem;
            }
            
            .hero-subtitle {
                font-size: 1rem;
            }
            
            .feature-services {
                grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
            }
        }
    </style>
</head>
<body>
    <% 
        // 检查用户是否已登录
        com.example.domain.User currentUser = (com.example.domain.User) session.getAttribute("user");
    %>
    
    <!-- 导航栏 -->
    <nav class="header-nav">
        <div class="nav-container">
            <a href="index.jsp" class="nav-brand">
                🛒 购物网
            </a>
            
            <!-- 搜索框 -->
            <div style="flex: 1; max-width: 400px; margin: 0 20px; position: relative;">
                <input type="text" placeholder="搜索商品..." style="width: 100%; padding: 10px 15px; padding-right: 40px; border-radius: var(--border-radius); border: 1px solid var(--gray-300); transition: var(--transition);">
                <button style="position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; color: var(--gray-500); cursor: pointer; font-size: 1.2rem;">
                    🔍
                </button>
            </div>
            
            <ul class="nav-links">
                <li><a href="index.jsp" class="active">首页</a></li>
                <li><a href="products/list.jsp">商品浏览</a></li>
                <li><a href="cart/view/cart.jsp">购物车</a></li>
                <% if (currentUser != null) { %>
                    <li><a href="admin/users/user_list.jsp">后台管理</a></li>
                <% } %>
            </ul>
            
            <div class="user-actions">
                <% if (currentUser != null) { %>
                    <span class="user-info">欢迎, <%= currentUser.getUsername() %>!</span>
                    <a href="auth/logout.jsp" class="btn btn-outline">退出</a>
                <% } else { %>
                    <a href="auth/login.jsp" class="btn btn-outline">登录</a>
                    <a href="auth/register.jsp" class="btn" style="margin-left: 10px;">注册</a>
                <% } %>
            </div>
        </div>
    </nav>
    
    <!-- 主体内容 -->
    <div class="container">
        <div class="main-content">
            <!-- 左侧分类导航 -->
            <div class="sidebar fade-in">
                <h3 class="section-title" style="font-size: 1.2rem; margin-top: 0;">商品分类</h3>
                <ul class="category-list-vertical">
                    <li class="category-item-vertical">
                        <a href="products/list.jsp">
                            <span class="category-icon-vertical">📱</span>
                            <span>手机数码</span>
                        </a>
                    </li>
                    <li class="category-item-vertical">
                        <a href="products/list.jsp">
                            <span class="category-icon-vertical">👕</span>
                            <span>服装鞋包</span>
                        </a>
                    </li>
                    <li class="category-item-vertical">
                        <a href="products/list.jsp">
                            <span class="category-icon-vertical">💻</span>
                            <span>电脑办公</span>
                        </a>
                    </li>
                    <li class="category-item-vertical">
                        <a href="products/list.jsp">
                            <span class="category-icon-vertical">🏠</span>
                            <span>家居用品</span>
                        </a>
                    </li>
                    <li class="category-item-vertical">
                        <a href="products/list.jsp">
                            <span class="category-icon-vertical">💄</span>
                            <span>美妆护肤</span>
                        </a>
                    </li>
                    <li class="category-item-vertical">
                        <a href="products/list.jsp">
                            <span class="category-icon-vertical">🎮</span>
                            <span>游戏娱乐</span>
                        </a>
                    </li>
                </ul>
            </div>
            
            <!-- 中间内容区域 -->
            <div class="content-area fade-in" style="animation-delay: 0.1s;">
                <!-- 轮播图区域 -->
                <div class="hero-section">
                    <div class="hero-banner">
                        <div class="hero-content">
                            <h2 class="hero-title">限时特惠</h2>
                            <p class="hero-subtitle">精选商品，品质保证，全场低至5折</p>
                            <a href="products/list.jsp" class="btn btn-lg" style="background-color: white; color: var(--primary-color); font-weight: 600;">
                                立即选购
                            </a>
                        </div>
                    </div>
                </div>
                
                <!-- 特色服务 -->
                <div class="feature-services">
                    <div class="service-card">
                        <div class="service-icon">🚚</div>
                        <div class="service-title">次日达</div>
                        <div class="service-desc">同城当日达，全国次日达</div>
                    </div>
                    <div class="service-card">
                        <div class="service-icon">💯</div>
                        <div class="service-title">正品保障</div>
                        <div class="service-desc">100%正品，假一赔十</div>
                    </div>
                    <div class="service-card">
                        <div class="service-icon">🔄</div>
                        <div class="service-title">7天无理由</div>
                        <div class="service-desc">轻松退换，购物无忧</div>
                    </div>
                    <div class="service-card">
                        <div class="service-icon">💳</div>
                        <div class="service-title">支付安全</div>
                        <div class="service-desc">多重支付方式，安全快捷</div>
                    </div>
                </div>
                
                <!-- 热门推荐 -->
                <h2 class="section-title">热门推荐</h2>
                <div class="product-grid">
                    <% 
                        Connection conn = null;
                        try {
                            conn = DBUtil.getConnection();
                            ProductDao productDao = new ProductDao();
                            List<Product> topProducts = productDao.getTopProducts();
                            
                            if (topProducts.isEmpty()) {
                    %>
                                <div class="card" style="padding: 2rem; text-align: center; grid-column: span 4;">
                                    <p>暂无热门推荐商品</p>
                                </div>
                    <% 
                            } else {
                                for (Product product : topProducts) {
                    %>
                    <div class="product-card fade-in" style="animation-delay: 0.2s;">
                        <div class="product-image">
                            <% if (product.getLogo() != null && !product.getLogo().isEmpty()) { %>
                                <img src="<%= request.getContextPath() + "/" + product.getLogo() %>" alt="<%= product.getProduct_name() %>">
                            <% } else { %>
                                <img src="<%= request.getContextPath() %>/assets/images/no-image.svg" alt="暂无图片" style="opacity: 0.5;">
                            <% } %>
                        </div>
                        <div class="product-info">
                            <div class="product-name"><%= product.getProduct_name() %></div>
                            <div class="product-intro"><%= product.getIntro() != null ? product.getIntro() : "暂无介绍" %></div>
                            <div class="product-price">
                                <% if (product.getSale_price() > 0) { %>
                                    <span class="sale-price">¥<%= product.getSale_price() %></span>
                                    <span class="original-price">¥<%= product.getPrice() %></span>
                                <% } else { %>
                                    ¥<%= product.getPrice() %>
                                <% } %>
                            </div>
                            <div class="product-actions">
                                <button class="btn btn-success" style="width: 100%;">立即购买</button>
                            </div>
                        </div>
                    </div>
                    <% 
                                }
                            }
                        } catch (Exception e) {
                    %>
                            <div class="card" style="padding: 2rem; text-align: center; grid-column: span 4;">
                                <p>加载热门推荐商品失败: <%= e.getMessage() %></p>
                            </div>
                    <% 
                        } finally {
                            if (conn != null) {
                                try { conn.close(); } catch (Exception e) { /* 忽略关闭连接的异常 */ }
                            }
                        }
                    %>
                </div>
            </div>
            
            <!-- 右侧用户信息面板 -->
            <div class="user-panel fade-in" style="animation-delay: 0.2s;">
                <h3 class="panel-title">用户中心</h3>
                
                <div class="panel-section">
                    <h4>我的交易</h4>
                    <ul class="panel-links">
                        <li>
                            <a href="#">
                                <span class="panel-icon">🛒</span>
                                <span>购物车</span>
                            </a>
                        </li>
                        <li>
                            <a href="#">
                                <span class="panel-icon">📦</span>
                                <span>我的订单</span>
                            </a>
                        </li>
                        <li>
                            <a href="#">
                                <span class="panel-icon">⭐</span>
                                <span>收藏夹</span>
                            </a>
                        </li>
                    </ul>
                </div>
                
                <div class="panel-section">
                    <h4>客户服务</h4>
                    <ul class="panel-links">
                        <li>
                            <a href="#">
                                <span class="panel-icon">❓</span>
                                <span>帮助中心</span>
                            </a>
                        </li>
                        <li>
                            <a href="#">
                                <span class="panel-icon">💬</span>
                                <span>在线咨询</span>
                            </a>
                        </li>
                        <li>
                            <a href="#">
                                <span class="panel-icon">📞</span>
                                <span>客服热线</span>
                            </a>
                        </li>
                    </ul>
                </div>
                
                <div class="panel-section">
                    <h4>账户设置</h4>
                    <ul class="panel-links">
                        <li>
                            <a href="#">
                                <span class="panel-icon">👤</span>
                                <span>个人信息</span>
                            </a>
                        </li>
                        <li>
                            <a href="#">
                                <span class="panel-icon">📍</span>
                                <span>收货地址</span>
                            </a>
                        </li>
                        <li>
                            <a href="#">
                                <span class="panel-icon">💳</span>
                                <span>支付设置</span>
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
    
    <!-- 页脚 -->
    <footer class="footer">
        <div class="container">
            <div class="footer-top">
                <div>
                    <a href="index.jsp" class="footer-logo">🛒 购物网</a>
                    <p style="margin-top: 1rem; color: var(--gray-400); font-size: 0.9rem;">
                        优质商品，优质服务，打造您的理想购物体验。
                    </p>
                </div>
                
                <div>
                    <h4 class="footer-heading">快速链接</h4>
                    <ul class="footer-links">
                        <li><a href="index.jsp">首页</a></li>
                        <li><a href="products/list.jsp">商品浏览</a></li>
                        <li><a href="#">关于我们</a></li>
                        <li><a href="#">联系我们</a></li>
                    </ul>
                </div>
                
                <div>
                    <h4 class="footer-heading">客户服务</h4>
                    <ul class="footer-links">
                        <li><a href="#">帮助中心</a></li>
                        <li><a href="#">售后政策</a></li>
                        <li><a href="#">配送信息</a></li>
                        <li><a href="#">常见问题</a></li>
                    </ul>
                </div>
                
                <div>
                    <h4 class="footer-heading">关注我们</h4>
                    <ul class="footer-links">
                        <li><a href="#">微信公众号</a></li>
                        <li><a href="#">微博</a></li>
                        <li><a href="#">抖音</a></li>
                        <li><a href="#">小红书</a></li>
                    </ul>
                </div>
            </div>
            
            <div class="footer-bottom">
                <p>&copy; 2025 购物网. 保留所有权利.</p>
            </div>
        </div>
    </footer>
</body>
</html>